package com.example.mform.controller;

import com.example.mform.entity.User;
import com.example.mform.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author shishuqian
 * date 2020/12/18
 * time 9:45
 **/
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("/findAll")
    public List<User> findAll(){
        return userService.findAll();
    }

    @GetMapping("/findById/{id}")
    public User findById(@PathVariable("id") Long id){
        return userService.findById(id);
    }

    @PostMapping("/save")
    public void save(@RequestBody User user){
        userService.save(user);
    }

    @PutMapping("/update")
    public void update(@RequestBody User user){
        userService.save(user);
    }

    @DeleteMapping("/deleteById/{id}")
    public void  deleteById(@PathVariable("id") Long id){
        userService.deleteById(id);
    }
}
